package com.example.android01.activity;

import static com.example.android01.api.ApiConfig.REGISTER;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.android01.R;
import com.example.android01.api.Api;
import com.example.android01.api.TtitCallback;
import com.example.android01.util.StringUtils;

import java.util.HashMap;

public class RegisterActivity extends BaseActivity {

    private EditText etAccount;
    private EditText etPwd;
    private Button btnResiter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        //绑定控件对象
        etAccount = findViewById(R.id.et_account);
        etPwd = findViewById(R.id.et_pwd);
        btnResiter = findViewById(R.id.btn_register);

        //点击事件
        btnResiter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //etAccount.getText().toString() 获取输入框文本； trim() 把文本前后空格去掉
                String account=etAccount.getText().toString().trim();
                String pwd=etPwd.getText().toString().trim();
                resiter(account,pwd);
            }
        });
    }

    private void resiter(String account,String pwd){
        if(StringUtils.isEmpty(account)){
            showToast("请输入账号");
            return;
        }
        if(StringUtils.isEmpty(account)){
            showToast("请输入密码");
        }

        HashMap<String,Object> params = new HashMap();
        params.put("mobile",account);
        params.put("password",pwd);
        Api.config(REGISTER,params).postRequest(this,new TtitCallback() {
            @Override
            public void onSuccess(String res) {

            }

            @Override
            public void onFailure(Exception e) {

            }
        });

    }
}